import sys

from typing import List

from alibabacloud_dingtalk.oauth2_1_0.client import Client as dingtalkoauth2_1_0Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_dingtalk.oauth2_1_0 import models as dingtalkoauth_2__1__0_models
from alibabacloud_tea_util.client import Client as UtilClient


dingtalk_access_token = ""
dingtalk_access_token_zhongxin = ""
dingtalk_access_token_nanxing = ""
dingtalk_access_token_jianhong = ""


class DingtalkCient:
    def __init__(self):
        pass

    @staticmethod
    def create_client() -> dingtalkoauth2_1_0Client:
        """
        使用 Token 初始化账号Client
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config()
        config.protocol = 'https'
        config.region_id = 'central'
        return dingtalkoauth2_1_0Client(config)

    @staticmethod
    def refresh_access_token() -> None:
        refresh_cx_token()
        refresh_nanxing_token()
        refresh_zhongxin_token()
        refresh_jianhong_token()


# 城乡access_token
def refresh_cx_token():
    client = DingtalkCient.create_client()
    get_access_token_request = dingtalkoauth_2__1__0_models.GetAccessTokenRequest(
        app_key='ding4eqe91l7f4bhkebc',
        app_secret='LFNi_IglTLoOyHw8R_Q8uJzOBy5kA_uhN5qFpxWE0CmOIHJzgljK_l14MiBmnYWH'
    )
    try:
        res = client.get_access_token(get_access_token_request)
        global dingtalk_access_token
        dingtalk_access_token = res.body.access_token
    except Exception as err:
        if not UtilClient.empty(err.code) and not UtilClient.empty(err.message):
            # err 中含有 code 和 message 属性，可帮助开发定位问题
            pass


# 南兴access_token
def refresh_nanxing_token():
    client = DingtalkCient.create_client()
    get_access_token_request = dingtalkoauth_2__1__0_models.GetAccessTokenRequest(
        app_key='ding46vbkvdkubdjzwgi',
        app_secret='oSOt7Zf9d9wOOQEirki3OuvudqhQcmRWomPAdDqQ9elirGYnel7Mv77uELZZC3db'
    )
    try:
        res = client.get_access_token(get_access_token_request)
        global dingtalk_access_token_nanxing
        dingtalk_access_token_nanxing = res.body.access_token
    except Exception as err:
        if not UtilClient.empty(err.code) and not UtilClient.empty(err.message):
            # err 中含有 code 和 message 属性，可帮助开发定位问题
            pass
        
# 建宏access_token
def refresh_jianhong_token():
    client = DingtalkCient.create_client()
    get_access_token_request = dingtalkoauth_2__1__0_models.GetAccessTokenRequest(
        app_key='dingofbgpqenkngwcxk5',
        app_secret='ibDocKjYjFNiz9qxsvzKKkJqwfha4mydlefF-wj8qo4bA7kzuOyfLGadwt5bkcIp'
    )
    try:
        res = client.get_access_token(get_access_token_request)
        global dingtalk_access_token_jianhong
        dingtalk_access_token_jianhong = res.body.access_token
    except Exception as err:
        if not UtilClient.empty(err.code) and not UtilClient.empty(err.message):
            # err 中含有 code 和 message 属性，可帮助开发定位问题
            pass

# 中信access_token


def refresh_zhongxin_token():
    client = DingtalkCient.create_client()
    get_access_token_request = dingtalkoauth_2__1__0_models.GetAccessTokenRequest(
        app_key='dingg5klzzoi78ljsflb',
        app_secret='AE7_vBWqkRf1b67dp4RhqC87Jepx-akAntsft_BhASVrN8u4KFyfkIhs6nVy6hUm'
    )
    try:
        res = client.get_access_token(get_access_token_request)
        global dingtalk_access_token_zhongxin
        dingtalk_access_token_zhongxin = res.body.access_token
    except Exception as err:
        if not UtilClient.empty(err.code) and not UtilClient.empty(err.message):
            # err 中含有 code 和 message 属性，可帮助开发定位问题
            pass
